#include <glut.h>

GLfloat eyex = 30;
GLfloat eyey = -30;
GLfloat eyez = 50;

void renderScene()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	glTranslatef(0, 0, -150);

	gluLookAt(eyex, eyey, eyez, 30, -30, -30, 0, 1, 0);

	//glRotatef(60, 0.f, 1.f, 0.f);
	glBegin(GL_TRIANGLE_FAN);
		// 1
		glColor3f(1, 0, 0);	// Red
		glVertex3f(0, 30, 0);
		glColor3f(0, 1, 0);	// Green
		glVertex3f(-30, -30, 30);
		glColor3f(0, 0, 1);	// Blue
		glVertex3f(30, -30, 30);
		// 2
		glColor3f(0, 1, 1);
		glVertex3f(0, -30, -30);
		// 3
		glColor3f(1, 1, 0);
		glVertex3f(-30, -30, 30);
		// 4
		glColor3f(1, 0, 1);
		glVertex3f(0, 30, 0);

	glEnd();

	glutSwapBuffers();
}

void processNormaKeys(unsigned char key, int x, int y)
{
	switch(key)
	{
	case 27:
		exit(0);
	}
}

void processSpecialKeys(int key, int x, int y)
{
	switch(key)
	{
	case GLUT_KEY_UP:
		eyey -= 5;
		break;
	case GLUT_KEY_DOWN:
		eyey += 5;
		break;
	case GLUT_KEY_LEFT:
		eyex += 5;
		break;
	case GLUT_KEY_RIGHT:
		eyex -= 5;
		break;
	case GLUT_KEY_HOME:
		eyez -= 5;
		break;
	case GLUT_KEY_END:
		eyez += 5;
		break;
	}
}

int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
	glutInitWindowSize(640, 640);
	glutCreateWindow("Ex2");
	glutDisplayFunc(renderScene);
	//glutReshapeFunc(renderScene);
	glutIdleFunc(renderScene);
	glutKeyboardFunc(processNormaKeys);
	glutSpecialFunc(processSpecialKeys);

	glMatrixMode(GL_PROJECTION);
	gluPerspective(	45, 1.0, 0, 400);

	glMatrixMode(GL_MODELVIEW);

	glutMainLoop();

	return 0;
}